<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Verify</title>
    <style>
        .v_code{
            width: 260px;
            height: 300px;
            background-color: #e5e5e5;
            margin: 50px auto;
            padding: 30px;
        }

        .code {
            font-style: italic;
            background-color: #f5f5f5;
            color: blue;
            font-size: 30px;
            letter-spacing: 3px;
            font-weight: bolder;
            /*float: left;*/
            cursor: pointer;
            padding: 0 5px;
            text-align: center;
        }
        .code_show a:hover{
            background-color: pink;
        }
        .code_show a:active{
            color: blue;
        }
    </style>
</head>
<body>
<div class="v_code">
    <div class="code_show">
        <span class="code" id="verifyCode"></span>
        <a id="linkbt">看不清换一张</a>
    </div>
    <div class="input_code">
        <label for="inputCode">验证码：</label>
        <input type="text" id="inputCode" />
        <span id="text_show"></span>
    </div>
    <input id="check" type="button" value="确定" />
</div>
<script>
    window.onload=function () {
        var res = getCode();
        function getCode() {
            var data=['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'];
            var str = '';
            for (var i = 0; i < 6; i++) {
                var num = Math.round(Math.random() * 15);
                str += data[num];
            }
            return str;
        }

        document.getElementById("verifyCode").innerText=res;


        document.getElementById('linkbt').onclick=function () {
            res=getCode();
            document.getElementById("verifyCode").innerText=res;
        }

        document.getElementById('check').onclick=function () {
                 var inputcode=document.getElementById('inputCode').value;
            if (res != inputcode) {
                alert("验证码不正确！");
                document.getElementById('inputCode').value = '';
                return false;
            }else {
                confirm("眼睛和智力在线");
            }
        }
    }
</script>
</body>
</html>